#delimit;
clear all;
version 13.1;
pause on;
program drop _all;
capture log close;
set more off;

/*INSERT FOLDER PATH*/
cd /;



use multi_level_dataset_005_field_vars.dta, clear;
drop if ovrlp_anypos==1;
keep id nbcites_it treat age yr srce_pmid srce_year treatX* case_code pubyear shldrs uprght rtrct_reason earlst;
gen subv_of_trth_loose=(shldrs==1|shldrs==2);
gen subv_of_trth_strct=shldrs==2;

xtreg nbcites_it treat i.age i.yr, fe i(id) cluster(case_code);
distinct case_code if e(sample);
estadd scalar nbcases=r(ndistinct);
distinct srce_pmid if e(sample);
estadd scalar nbsource=r(ndistinct);
estimates save estimates/ols_main.ster, replace;

xtreg nbcites_it treat i.age i.yr if rtrct_reason!=10, fe i(id) cluster(case_code);
distinct case_code if e(sample);
estadd scalar nbcases=r(ndistinct);
distinct srce_pmid if e(sample);
estadd scalar nbsource=r(ndistinct);
estimates save estimates/ols_main_nonmissing.ster, replace;

xtreg nbcites_it treat treatXshky_shldrs treatXabsnt_shldrs i.age i.yr if rtrct_reason!=10, fe i(id) cluster(case_code);
distinct case_code if e(sample);
estadd scalar nbcases=r(ndistinct);
distinct srce_pmid if e(sample);
estadd scalar nbsource=r(ndistinct);
estimates save estimates/ols_main_shldrs_nonmissing.ster, replace;

xtreg nbcites_it treat treatXabsnt_shldrs i.age i.yr if subv_of_trth_loose==1, fe i(id) cluster(case_code);
distinct case_code if e(sample);
estadd scalar nbcases=r(ndistinct);
distinct srce_pmid if e(sample);
estadd scalar nbsource=r(ndistinct);
estimates save estimates/ols_main_loose_shldrs.ster, replace;

xtreg nbcites_it treat i.age i.yr if (earlst==1 & (shldrs==1|shldrs==2)), fe i(id) cluster(case_code);
distinct case_code if e(sample);
estadd scalar nbcases=r(ndistinct);
distinct srce_pmid if e(sample);
estadd scalar nbsource=r(ndistinct);
estimates save estimates/ols_main_shldrs_nonmissing_earlst.ster, replace;

xtreg nbcites_it treat treatXbigfraud i.age i.yr if subv_of_trth_strct==1, fe i(id) cluster(case_code);
distinct case_code if e(sample);
estadd scalar nbcases=r(ndistinct);
distinct srce_pmid if e(sample);
estadd scalar nbsource=r(ndistinct);
estimates save estimates/ols_main_bigfraud_strct.ster, replace;




set emptycells drop;
set matsize 1000;
estimates drop _all;

estimates use  estimates/ols_main.ster;
eststo;
estimates use  estimates/ols_main_nonmissing.ster;
eststo;
estimates use  estimates/ols_main_shldrs_nonmissing.ster;
eststo;
estimates use  estimates/ols_main_loose_shldrs.ster;
eststo;
estimates use  estimates/ols_main_shldrs_nonmissing_earlst.ster;
eststo;
estimates use  estimates/ols_main_bigfraud_strct.ster;
eststo;


esttab *, keep(treat treatXshky_shldrs treatXabsnt_shldrs treatXbigfraud) varwidth(25) nonumber noobs nogaps nodep label b(%5.3f) se(%5.3f) star(� 0.10 * 0.05 ** 0.01) compress scalars("nbcases Nb. of Retraction Cases" "nbsource Nb. of Source Articles" "N_g Nb. of Related/Control Articles" "N Nb. of Article-Year Obs." "ll Log Likelihood") sfmt(%10.0fc %10.0fc %10.0fc %10.0fc %10.0fc) mlabels("(1)" "(2)" "(3)" "(4)" "(5)" "(6)" "(7)" "(8)" "(9)") eqlabels(none);
esttab * using tables/table_ols_main_reasons_intr.rtf, keep(treat treatXshky_shldrs treatXabsnt_shldrs treatXbigfraud) varwidth(25) nonumber noobs nogaps nodep label b(%5.3f) se(%5.3f) star(� 0.10 * 0.05 ** 0.01) compress scalars("nbcases Nb. of Retraction Cases" "nbsource Nb. of Source Articles" "N_g Nb. of Related/Control Articles" "N Nb. of Article-Year Obs." "ll Log Likelihood") sfmt(%10.0fc %10.0fc %10.0fc %10.0fc %10.0fc) mlabels("(1)" "(2)" "(3)" "(4)" "(5)" "(6)" "(7)" "(8)" "(9)") eqlabels(none) replace;

